package com.gxa.modules.community.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.community.entity.*;
import com.gxa.modules.community.service.MonthMangeService;
import com.gxa.modules.community.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "月卡管理")
public class MonthManageController {
    @Autowired
    private MonthMangeService monthMangeService;
    @ApiOperation("月卡管理 查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "monthlyCardStatus",value ="月卡状态",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "monthlyCardNumber",value ="月卡编号",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "communityId",value ="小区id",dataType ="int"),
    }
    )
    @GetMapping("/monthmanage/list")
    public Result<List<MonthManage>> list01(@RequestParam @ApiIgnore Map<String,Object> params){
        Result<List<MonthManage>> r=Result.success();
        String page1=(String) params.get("page");
        String limit1=(String)params.get("limit");
        Integer page=Integer.valueOf(page1);
        Integer limit=Integer.valueOf(limit1);
        try {
            PageHelper.startPage(page,limit);
            List<MonthManage> monthManages = this.monthMangeService.queryByPage(params);
            PageInfo<MonthManage> pageInfo = new PageInfo<>(monthManages);
            long total = (int) pageInfo.getTotal();
            r=Result.success(monthManages,total);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("月卡管理 添加")
    @PostMapping("/monthmanage/add")
    public Result<List<MonthManageAU>> monthMangeAdd(@RequestBody MonthManageAU monthManageAU){

        System.out.println(monthManageAU);
        Result<List<MonthManageAU>> r=Result.success();
        try {
            this.monthMangeService.monthMangeAdd(monthManageAU);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("月卡管理 修改")
    @PutMapping("/monthmanage/update")
    public Result<List<MonthManageAU>> monthMangeUpdate(@RequestBody MonthManageAU monthManageAU){
        System.out.println(monthManageAU);
        Result<List<MonthManageAU>> r=Result.success();
        try {
            this.monthMangeService.monthMangeUpdate(monthManageAU);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("月卡管理 删除")
    @DeleteMapping("/monthmanage/delete")
    public Result<List<MonthManageAU>> monthMangeDelete(Integer id){
        Result<List<MonthManageAU>> r=Result.success();
        try {
            this.monthMangeService.monthMangeDelete(id);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
    @ApiOperation("月卡管理 批量删除")
    @DeleteMapping("/monthmanage/ids/delete")
    public Result<List<MonthManageAU>> monthMangeDeleteIds(@RequestBody List<Integer> ids){
        Result<List<MonthManageAU>> r=Result.success();
        try {
            this.monthMangeService.monthMangeDeleteIds(ids);
            r=Result.success();
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
}
